<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 16/4/12
 * Time: 下午2:08
 */
class SendMessage
{
    public static function sendSms($type,$order_id){
        try{
            $order = Orders::where('order_id',$order_id)->first();
            if(!is_null($order)){
                /*判断上门还是到店*/
                if($order->place == 1){ //上门
                    $content_model = Config::get('sms.car_content');
                    $car = MaintenanceCars::where('id',$order->car_id)->first();
                    $replace = array(
                        'order_id' => $order->order_id,
                        'book_date' => $order->book_time,
                        'book_time' => $order->book_hour,
                        'amount' => $order->payable_amount/100,
                        'url' =>  Config::get('config.c_url').'order/feedBackOrder?order_id='.$order->order_id,
                        'car_no' => $car->car_no
                    );
                }else{ //到店
                    $content_model = Config::get('sms.shop_content');
                    $shop = MaintenanceShops::where('id',$order->shop_id)->first();
                    $replace = array(
                        'order_id' => $order->order_id,
                        'book_date' => $order->book_time,
                        'book_time' => $order->book_hour,
                        'shop_address' => $shop->name.'('.$shop->address.')',
                        'amount' => $order->payable_amount/100,
                        'url' => Config::get('config.c_url').'order/feedBackOrder?order_id='.$order->order_id,
                    );
                }
                $sms_content = $content_model[$type];
                $sms_content = strtr($sms_content,$replace);

                $code = Sms::send_message('010',$order->phone,$sms_content);
            }else{
                $code = -1;
            }
        } catch (Exception $e) {
            $code = -2;
        }
        return $code;
    }
}